var draw = draw||{};


draw.drawLine =  function(id,lineData) {
		var xaxis=null;
		if(lineData.xaxis)
			xaxis = lineData.xaxis;// [[1, '1月'], [2, '2月'], [3, '3月'], [4, '4月'], [5, '5月'], [6, '6月'], [7, '7月'], [8, '8月'], [9, '9月'], [10, '10月'], [11, '11月'], [12, '12月']];
		var placeholder = $('#'+id);
		$("<div id='tooltip'></div>").css({
			position: "absolute",
			display: "none",
			border: "1px solid #fdd",
			padding: "2px",
			"background-color": "#fee",
			opacity: 0.80
		}).appendTo("body");
		
		placeholder.bind("plothover", function (event, pos, item) {
			if (item) {
					y = item.datapoint[1].toFixed(2);
				$("#tooltip").html(item.series.label + ": " + y)
					.css({top: item.pageY+5, left: item.pageX+5})
					.fadeIn(200);
			} else {
				$("#tooltip").hide();
			}
		});
		var options = {
				 xaxis: {ticks: xaxis},
				series: {
					lines: { show: true },
					points: { show: true,radius: 4}
				},
				grid: {
					hoverable: true,
					clickable: true
				}
			};
		if(lineData.lineType=='time'){
			options =  options + {
					xaxis:{   
						mode: "time",  
						timeformat: "%Y-%m-%d %H:%i",  
						tickFormatter: function (val, axis) {  
							
							var d = new Date(val);  
							return d.toLocaleTimeString();//转为当地时间格式  
						}  
					}
			};
		}
		
		var lineDataSet = [];
		for(var index=0;index<lineData.data.length;index++){
			var itemData = [];
			var lineItem = lineData.data[index];
			
			for (var i = 0; i < lineItem.length; i++) {
				
				itemData[i] = [lineItem[i].key, lineItem[i].value];
			}
			lineDataSet[index] = {label: lineData.title[index], data: itemData};
		}
		$.plot(placeholder, lineDataSet, options);
	};
	
	draw.defaultLine = function(id,param,url){
		commonutil.doAjax(url,param,function(data){
			draw.drawLine(id,data);
		},'json');
	};